package com.TeamJigsaw.DanteTrail.Views;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.ActionListener;

import javax.swing.*;

import com.TeamJigsaw.DanteTrail.Views.Interfaces.ProfessionInterface;

import net.miginfocom.swing.MigLayout;
import javax.swing.border.TitledBorder;
import java.awt.event.ActionEvent;
import java.awt.Color;

public class ProfessionView extends JPanel implements ProfessionInterface{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JButton btnBack, btnNext;
	private ButtonGroup group;
	private JRadioButton rdbtnNewRadioButton,rdbtnNewRadioButton_1,rdbtnNewRadioButton_2;
	private JPanel panel;
	private JPanel panel_1;
	private JComboBox comboBox;
	private JComboBox comboBox_1;
	private JLabel lblNewLabel;
	private JLabel lblNewLabel_1;
	private String[] rations, paces;
	private int profession = 0;
	private String htmlStart, htmlEnd;
	public ProfessionView()
	{
		htmlStart = "<html><font size=\"4\" color=\"#FFFFFF\"><b>";
		htmlEnd = "</b></font></html>";
		setSize(new Dimension(700,700));
		
		initialize();
	}
	
	private void initialize()
	{
		setLayout(new MigLayout("", "[100px:100px:100px][75:75:75][200px:200px:200px][100px:100px:100px][100px:100px:100px]", "[50px:50px:50px,grow][200px:200px:200px][20:20:20][][20:20:20][]"));
		profession = 1;
		//Group the radio buttons.
	    group = new ButtonGroup();
	    rations = new String[]{"Well Fed", "Normal", "Meager","Starving","None"};
	    paces = new String[]{"Blazing","Fast", "Normal", "Slow"};
	    
	    panel = new JPanel();
	    panel.setBorder(new TitledBorder(null, "Choose Your Profession", TitledBorder.LEADING, TitledBorder.ABOVE_TOP, null, Color.WHITE));
	    panel.setOpaque(false);
	    add(panel, "cell 2 1 2 1,grow");
	    panel.setLayout(new MigLayout("", "[grow][5px]", "[25px][25px][][][][]"));
	    rdbtnNewRadioButton = new JRadioButton(htmlStart + "Corrupt Politician: Gives more money" + htmlEnd);
	    rdbtnNewRadioButton.addActionListener(new ActionListener() {
	    	@Override
			public void actionPerformed(ActionEvent e) {
	    		profession = 1;
	    	}
	    });
	    panel.add(rdbtnNewRadioButton, "cell 0 0 2 1,growx,aligny top");
	    group.add(rdbtnNewRadioButton);
	    
	    rdbtnNewRadioButton_1 = new JRadioButton(htmlStart + "Con Artist: Better Shop prices and trading" + htmlEnd);
	    rdbtnNewRadioButton_1.addActionListener(new ActionListener() {
	    	@Override
			public void actionPerformed(ActionEvent e) {
	    		profession = 2;
	    	}
	    });
	    panel.add(rdbtnNewRadioButton_1, "flowx,cell 0 2,alignx left,aligny top");
	    group.add(rdbtnNewRadioButton_1);
	    rdbtnNewRadioButton.setSelected(true);
	    
	    rdbtnNewRadioButton_2 = new JRadioButton(htmlStart + "Murderer: Can get more food from hunting" + htmlEnd);
	    rdbtnNewRadioButton_2.addActionListener(new ActionListener() {
	    	@Override
			public void actionPerformed(ActionEvent e) {
	    		profession = 3;
	    	}
	    });
	    panel.add(rdbtnNewRadioButton_2, "cell 0 4,alignx left,aligny top");
	    group.add(rdbtnNewRadioButton_2);
	    
	    panel_1 = new JPanel();
	    panel_1.setOpaque(false);
	    panel_1.setBorder(new TitledBorder(null, "Set Initial Rations and Pace", TitledBorder.LEADING, TitledBorder.ABOVE_TOP, null, Color.WHITE));
	    add(panel_1, "cell 2 3 2 1,grow");
	    panel_1.setLayout(new MigLayout("", "[200px:200px:200px]", "[][][][][]"));
	    
	    lblNewLabel = new JLabel(htmlStart + "Rations" + htmlEnd);
	    panel_1.add(lblNewLabel, "cell 0 0");
	    comboBox = new JComboBox(rations);
	    comboBox.setSelectedIndex(1);
	    panel_1.add(comboBox, "cell 0 1,growx");
	    
	    lblNewLabel_1 = new JLabel(htmlStart + "Pace" + htmlEnd);
	    panel_1.add(lblNewLabel_1, "cell 0 3");
	    
	    comboBox_1 = new JComboBox(paces);
	    comboBox_1.setSelectedIndex(1);
	    panel_1.add(comboBox_1, "cell 0 4,growx");
	    
	    btnBack = new JButton("Back");
	    btnBack.addActionListener(new ActionListener() {
	    	@Override
			public void actionPerformed(ActionEvent e) {
	    	}
	    });
	    add(btnBack, "flowx,cell 1 5,growx");
	    
	    btnNext = new JButton("Next");
	    add(btnNext, "cell 4 5,growx");
	}

	@Override
	public int getProfession() {
		return profession;
	}

	@Override
	public void setNextListener(ActionListener listen) {
		btnNext.addActionListener(listen);
		
	}
	
	@Override
	public void setBackListener(ActionListener listen) {
		// TODO Auto-generated method stub
		btnBack.addActionListener(listen);
	}

	@Override
	public int getRation() {
		if(comboBox.getSelectedItem() == null) {
			return -1;
		}
		else if(comboBox.getSelectedItem().equals("None")) {
			return 0;
		}
		else if(comboBox.getSelectedItem().equals("Starving")) {
			return 1;
		}
		else if(comboBox.getSelectedItem().equals("Normal")) {
			return 3;
		}
		else if(comboBox.getSelectedItem().equals("Well Fed")) {
			return 4;
		}
		else if(comboBox.getSelectedItem().equals("Meager")) {
			return 2;
		}
		return 0;
	}

	@Override
	public int getPace() {
		if(comboBox_1.getSelectedItem() == null) {
			return -1;
		}
		else if(comboBox_1.getSelectedItem().equals("Slow")) {
			return 5;
		}
		else if(comboBox_1.getSelectedItem().equals("Normal")) {
			return 10;
		}
		else if(comboBox_1.getSelectedItem().equals("Fast")) {
			return 15;
		}
		else if(comboBox_1.getSelectedItem().equals("Blazing")) {
			return 20;
		}
		return 0;
	}
	
	@Override
	public boolean listenersExist() {
		if(btnNext.getActionListeners().length > 0)
		{
			return true;
		}
		return false;
	}

	@Override
	public void paintComponent(Graphics g) {
		ImageIcon img = new ImageIcon("resources\\stone_texture.png");
	    g.drawImage(img.getImage(), 0, 0, null);
	  }
}
